<?php
declare(strict_types=1);

namespace App\Controller\WebApi\v1;

use App\Controller\AbstractController;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Controller;
use App\Middleware\WebApiMiddleware;
use Hyperf\HttpServer\Annotation\Middleware;
use Service\GoodsService\GoodsClassService;
use Hyperf\Di\Annotation\Inject;

/**
 * 商品分类
 * @author huj
 * @Controller(prefix="/webapi/v1/goodsclass")
 * @Middleware(WebApiMiddleware::class)
 */
class GoodsClassController extends AbstractController 
{
    /**
     * 通过 `@Inject` 注解注入由 `@var` 注解声明的属性类型对象
     * @Inject()
     * @var GoodsClassService
     */
    protected $goodsClassService;

    /**
     * 获取商品分类
     * @RequestMapping(path="getclass", methods="get,post")
     */
    public function getclass(RequestInterface $request)
    {
        $param        = $request->inputs(['pid','noClass','cid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->goodsClassService->getclass($param);
    }

    /**
     * 根据分类获取热门品牌和热门分类
     * @RequestMapping(path="gethot", methods="get,post")
     */
    public function gethot(RequestInterface $request)
    {
        $param        = $request->inputs(['class_id']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->goodsClassService->gethot($param);
    }

    /**
     * 获取商品分类
     * @RequestMapping(path="getIndexBarClass", methods="get,post")
     */
    public function getIndexBarClass(RequestInterface $request)
    {
        $param        = $request->inputs(['pid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->goodsClassService->getclass($param);
    }

    /**
     * 获取商品分类Banner
     * @RequestMapping(path="getClassBanner", methods="get,post")
     */
    public function getClassBanner(RequestInterface $request)
    {
        $param        = $request->inputs(['class_id','mn_sid','cid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->goodsClassService->getClassBanner($param);
    }

    /**
     * 获取商品分类及商品数量
     * @RequestMapping(path="getClassNumber", methods="get,post")
     */
    public function getClassNumber(RequestInterface $request)
    {
        $param        = $request->inputs(['pid','cid','mn_sid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->goodsClassService->getClassNumber($param);
    }

    /**
     * 获取所有二级分类
     * @RequestMapping(path="getChildrenClass", methods="get,post")
     */
    public function getChildrenClass(RequestInterface $request)
    {
        $param        = $request->inputs(['cid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->goodsClassService->getChildrenClass($param);
    }
}